package com.zuorenke.vertx.handler;

import com.zuorenke.help.HandlerUtils;
import io.vertx.core.Handler;
import io.vertx.ext.web.RoutingContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import static io.vertx.core.http.HttpHeaders.*;
import static io.vertx.core.http.HttpHeaders.ACCESS_CONTROL_MAX_AGE;

/**
 * @author Z.R.K
 * @description
 * @create 2019-05-16 08:57:45
 **/
@Component
@Slf4j
public class ResponseInitPostHandler implements Handler<RoutingContext> {
	
	@Override
	public void handle(RoutingContext ctx) {
//		log.info("begin ... {}", 111);
//		log.info("do ResponseInitPostHandler");
//		ctx.response().putHeader(, )
		ctx.response().headers().add(CONTENT_TYPE, "application/json; charset=utf-8");
		ctx.response().headers().add(ACCESS_CONTROL_ALLOW_ORIGIN, "*");
		ctx.response().headers().add(ACCESS_CONTROL_ALLOW_METHODS, "POST, GET, OPTIONS, PUT, DELETE, HEAD");
		ctx.response().headers().add(ACCESS_CONTROL_ALLOW_HEADERS,
				"X-PINGOTHER, Origin,Content-Type, Accept, X-Requested-With, Dev, Authorization, Version, Token");
		ctx.response().headers().add(ACCESS_CONTROL_MAX_AGE, "1728000");
		HandlerUtils.next(ctx);
	}
}
